/**
 * Project   : android-utility
 * Package   : org.basagee.adapters
 * File name : DynamicListAdapter.java
 * Author    : Basagee
 * Date      : 2011. 4. 15.

 * Copyright
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.basagee.adapters;

import java.util.ArrayList;

import android.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * @author Basagee
 *
 */
public class DynamicListAdapter extends BaseAdapter {
	private LayoutInflater mInflater;
	private ArrayList<String> mRowList;
	private int resourceLayoutId;

	public DynamicListAdapter(Context context, int textViewResourceId, ArrayList<String> rowList) {
		mInflater = (LayoutInflater)context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
		resourceLayoutId = textViewResourceId;
		mRowList = rowList;
	}

	/* (non-Javadoc)
	 * @see android.widget.Adapter#getCount()
	 */
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mRowList.size();
	}

	/* (non-Javadoc)
	 * @see android.widget.Adapter#getItem(int)
	 */
	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return mRowList.get(position);
	}

	/* (non-Javadoc)
	 * @see android.widget.Adapter#getItemId(int)
	 */
	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	/* (non-Javadoc)
	 * @see android.widget.Adapter#getView(int, android.view.View, android.view.ViewGroup)
	 */
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		if(convertView == null)
		{
			convertView = mInflater.inflate(resourceLayoutId, parent, false);
		}
		
		TextView tvTextLabel = (TextView)convertView.findViewById(org.basagee.activities.R.id.textLabel);
		tvTextLabel.setText(mRowList.get(position));
		
		return convertView;
	}

}
